package com.tss.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tss.pojo.Certificate;
import com.tss.pojo.CertificateResult;
import com.tss.pojo.Result;
import com.tss.service.CertificateService;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("certificate")
public class CertificateController {

	
	@Autowired
	private CertificateService certificateService;
	
	/**
	 * 创建证书
	 * @param id
	 * @return
	 */
	@RequestMapping("create")
	@ResponseBody
	public String create(Long id){
		Result result = new Result();
		if(id==null){
			result.setErrorMessage("参数错误！");
			return result.toString();
		}
		
		Certificate certificate = new Certificate();
		certificate.setId(id);
		result=certificateService.createCertificate(certificate);
		return result.toString();
	}
	
	/**
	 * 待生成证书列表
	 * @return
	 */
	@RequestMapping("list")
	@ResponseBody
	public String listUnissuedCertificate(){
		//PageHelper.startPage(pageNum, pageSize);
		List<CertificateResult> list = certificateService.listCertificate(null);
		//PageInfo<ApplyResult> p = new PageInfo<>(list);
		//return JSONObject.fromObject(p).toString();
		return JSONArray.fromObject(list).toString();
	}
	

	
	
	
	
}
